package com.example.katalksample;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	ListView listview;
	TextView messageView;
	TextView addView; 
	
	ArrayAdapter<String> mAdapter;
	String[] mdata = { "신민아", "손예진", "유인나", "한혜진",
					   "고준희", "한효주", "박한별", "신세경", 
					   "이연희", "송혜교", "강예빈", "한가인" };
	
	ArrayList<String> mList = new ArrayList<String>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// 타이틀바 없애기
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		listview = (ListView)findViewById(R.id.MyListView);
		messageView = (TextView)findViewById(R.id.message);
		
		addView = (TextView)findViewById(R.id.addPerson);
		
		Button btn = (Button)findViewById(R.id.addbtn);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String text = addView.getText().toString();
				if(text != null && !text.equals(""))
				{
					mAdapter.add(text);
				}
			}
		});
		
		// 리스트 얻어오기
		setData();
		
		mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mList);
		listview.setAdapter(mAdapter);
		listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				// TODO Auto-generated method stub
				messageView.setText("눌러진 사람 : " + mAdapter.getItem(position));
			}
		});
	}
	
	private void setData()
	{
		for(String str : mdata)
		{
			mList.add(str);
		}
	}
}
